package com.woniuxy.classteacher.mqreceiver;

import com.rabbitmq.client.Channel;
import com.woniuxy.classteacher.uitility.SendMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Auther: 牟强
 * @Date: 2020/8/1/001 14:47
 * @Description:
 */
@Component
public class PhoneCodeMQ {
    @RabbitListener(queues = "code")
    public void received(Map<String, String> phoneAndcode, Channel channel, Message message) throws IOException {
        System.out.println("收到发送code请求");
        String phone = phoneAndcode.get("phone");
        String code = phoneAndcode.get("code");
        System.out.println(phone + ":" + code);
        SendMessage.sendSms(phone, code);
        //手动确认消息，移除消息队列
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        System.out.println("短信验证码发送完成");
    }

}
